#include <unistd.h>
#include <sys/wait.h>
static int pfd1[2], pfd2[2];

void exitPrint(const char *str);
void exitPrint(const char *str){
        printf("%s\n", str);
        exit(0);
}

void TELL_WAIT(void){
    if(pipe(pfd1) < 0 || pipe(pfd2) < 0){
        exitPrint("pipe error");
    }
}

void TELL_PARENT(pid_t pid){
    if(write(pfd2[1], "c", 1) != 1){
        exitPrint("wirte error");
    }
}

void WAIT_PARENT(void){
    char c;
    if(read(pfd1[0], &c, 1) != 1){
        exitPrint("read error");
    }
    if(c != 'p'){
        exitPrint("wait parent error");
    }
}

void TELL_CHILD(pid_t pid){
    if(write(pfd1[1], "p", 1) != 1){
        exitPrint("write error");
    }
}

void WAIT_CHILD(void){
    char c;
    if(read(pfd2[0], &c, 1) != 1){
        exitPrint("read error");
    }
    if(c != 'c'){
        exitPrint("wait child error");
    }
}